# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

    def __str__(self):
        s = ''
        tmp = self
        while tmp:
            s += str(tmp.val) + ' '
        return s

def create_list(vals: list) -> ListNode:
    if len(vals) == 0: return None
    head = ListNode(vals[0])
    tmp = head
    for val in vals[1:]:
        tmp.next = ListNode(val)
        tmp = tmp.next
    return head
